package com.leather.admin.controller;

import com.leather.admin.feignclient.GoodsTypeClient;
import com.leather.common.entity.GoodsType;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("admin/goodstype")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeClient goodsTypeClient;

    @RequiresPermissions("admin:goodstype:index")
    @GetMapping("/index")
    public String index() {
        return "goodstype/index";
    }


    @RequiresPermissions("admin:goodstype:create")
    @GetMapping("/create")
    public String create() {
        return "goodstype/create";
    }

    @RequiresPermissions("admin:goodstype:index")
    @GetMapping("/list")
    @ResponseBody
    public Object list() {
        return goodsTypeClient.goodsTypeIndex();
    }

    @ResponseBody
    @PostMapping("/create")
    @RequiresPermissions("admin:goodstype:create")
    public Object addJob(String goodsTypeName ) {
        System.out.println(goodsTypeName);
        GoodsType goodsType = new GoodsType();
        goodsType.setId(0);
        goodsType.setGoodsTypeName(goodsTypeName);
       return goodsTypeClient.addGoodsType(goodsType);
    }

}
